home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 405_01 / dmanParser.y < prev    next >
Encoding:
Text File  |  1993-07-17  |  6.4 KB  |  244 lines

  1. /* @(#) dmanParser.y YaccSource asterisk 1.14 93/07/05 16:13:06 (SCCS/s.dmanParser.y) */
  2. /*
  3.  * Nom du Fichier :     |>nom_fichier<|
  4.  * Titre :         |>Titre<|
  5.  * Auteur:        |>auteur<|        
  6.  * Date de creation :    |>dateCreation<|
  7.  */
  8. /* Description :
  9.  *    Document de reference : |>doc<|
  10.  *    Objet : |>objet<|
  11.  *
  12.  */
  13. /* 
  14.  * historique :
  15.  * |>date<|    |>auteur<|    |>objet<|
  16.  */
  17. /* -------------- declaration section -------------- */
  18. %name DmanParser
  19. %union {
  20.     char theChar;
  21.     char *theString;
  22.     }
  23. %header{
  24. typedef YY_DmanParser_STYPE TokenValue;
  25. typedef
  26.   struct
  27.     { int first_line,last_line,first_column,last_column;
  28.       char *text;
  29.     } TokenLocation;
  30. %}
  31. %{
  32. static char SccsId[]="@(#) dmanParser.y YaccSource asterisk 1.14 93/07/05 16:13:06 (SCCS/s.dmanParser.y)";
  33. %}
  34. %define LSP_NEEDED
  35. %define DEBUG 1
  36. %define LTYPE TokenLocation
  37. %define LLOC theTokenLocation
  38. %define LVAL theTokenValue
  39. %define LEX Scan
  40. %define LEX_BODY =0
  41. %define ERROR_BODY =0
  42. %define ERROR PrintError
  43. %define NERRS errorCount
  44. %define DEBUG_FLAG debugFlag
  45. %define MEMBERS  
  46. %define PARSE Parse 
  47. %define PARSE_PARAM 
  48. %define CONSTRUCTOR_PARAM 
  49. %define CONSTRUCTOR_INIT 
  50. %define CONSTRUCTOR_CODE 
  51.  
  52. %start man_page
  53. %token CMD_HEADER  CMD_BAD CMD_SECTION CMD_SSECTION
  54. %token TOK_ITEM1 TOK_ITEM2 TOK_ITEM3 TOK_ITEM_BAD
  55. %token TOK_INDENT1 TOK_INDENT2 TOK_INDENT3 TOK_INDENT_BAD
  56. %token TOK_LF TOK_INF TOK_SUP TOK_DQUOTE TOK_SPACE TOK_BEGIN TOK_END
  57. %token TOK_BAD
  58. %token <theChar> TOK_CHAR 
  59. %token <theString> TOK_COMPOSED2 TOK_COMPOSED1
  60.     /* -------------- rules section -------------- */
  61. %%
  62. man_page    : header_page  corps_page 
  63.         ;
  64. /* SAUTS DE LIGNE , ESPACES */
  65. sauts_ligne    :    TOK_SPACE TOK_LF
  66.         |    TOK_LF
  67.         |    sauts_ligne TOK_LF
  68.         ;
  69.  
  70. sauts0_ligne    :    sauts_ligne
  71.         |
  72.         ;
  73.  
  74. espaces        : TOK_SPACE
  75.         ;
  76.  
  77. espaces0    : espaces
  78.         |
  79.         ;
  80.  
  81. /* textes */
  82.  
  83. un_char_symbol    : TOK_CHAR {printf("%c",$<theChar>1);}
  84.         ;
  85. un_char_mot    :TOK_CHAR {switch($<theChar>1) 
  86.                              {case '.': case '-': case ' ': printf("\\%c",$<theChar>1); break;
  87.                   case '"': printf("\"");break;
  88.                   case '\\': printf("\\e");break;
  89.                               default:printf("%c",$<theChar>1);}
  90.                            }
  91.         | TOK_COMPOSED2 {printf("%c\\*%s",$<theString>1[0], &$<theString>1[1]);}
  92.         | TOK_COMPOSED1 {printf("\\%s",$<theString>1);}
  93.         ;
  94.  
  95. un_space_texte    : espaces {printf(" ");}
  96.         ;
  97. un_char_texte    : un_char_mot
  98.         | un_space_texte
  99.         ;
  100. argument_nom    : symbole {printf(" ");}
  101.         ;
  102. argument_texte    :  TOK_DQUOTE {printf("\"");} texte_quote TOK_DQUOTE {printf("\" ");}
  103.         ;
  104. symbole        : un_char_symbol
  105.         | symbole un_char_symbol
  106.         ;
  107. /* texte normal */
  108. un_meta_char : un_char_mot
  109.         | texte_italique
  110.         | texte_bold
  111.         ;
  112. meta_mot    :  un_meta_char
  113.         | meta_mot un_meta_char
  114.         ;
  115. texte        : un_char_texte
  116.         | texte un_char_texte
  117.         ;
  118. texte_riche    : meta_mot
  119.         | texte_riche un_space_texte meta_mot
  120.         ;
  121.  
  122. texte_bold    : TOK_DQUOTE {printf("\\fB");} texte {printf("\\fP");} TOK_DQUOTE
  123.         ;
  124. texte_italique    : TOK_INF {printf("\\fI");} texte TOK_SUP {printf("\\fP");}
  125.         ;
  126. /* texte quote */
  127. un_space_texte_quote : espaces {printf(" ");}
  128.         ;
  129.         
  130. un_char_mot_quote    : TOK_CHAR {switch($<theChar>1) 
  131.                              {case '\\':   printf("\\\\e"); break;
  132.                   case '"': printf("\"\"");break;
  133.                   case '-': case '.': case ' ': printf("\\\\%c",$<theChar>1);break;
  134.                               default:printf("%c",$<theChar>1);}
  135.                            }
  136.         | TOK_COMPOSED2 {printf("%c\\\\*%s",$<theString>1[0], &$<theString>1[1]);}
  137.         | TOK_COMPOSED1 {printf("\\\\%s",$<theString>1);}
  138.         ;
  139. un_char_texte_quote : un_char_mot_quote
  140.         | un_space_texte_quote
  141.         ;
  142. un_meta_char_quote : un_char_mot_quote
  143.         | texte_italique_quote
  144.         | texte_bold_quote
  145.         ;
  146.  
  147. meta_mot_quote    :  un_meta_char_quote
  148.         | meta_mot_quote un_meta_char_quote
  149.         ;
  150. texte_quote    : un_char_texte_quote
  151.         | texte_quote un_char_texte_quote
  152.         ;
  153. texte_riche_quote    : meta_mot_quote
  154.         | texte_riche_quote un_space_texte_quote meta_mot_quote
  155.         ;
  156.  
  157. texte_bold_quote    : TOK_DQUOTE {printf("\\\\fB");} texte_quote {printf("\\\\fP");} TOK_DQUOTE
  158.         ;
  159. texte_italique_quote    : TOK_INF {printf("\\\\fI");} texte_quote TOK_SUP {printf("\\\\fP");}
  160.         ;
  161.         
  162.  
  163. /* HEADER */
  164. header_page    : sauts0_ligne  CMD_HEADER {printf(".TH ");} espaces argument_nom espaces argument_nom espaces0 argument_texte espaces0 argument_texte espaces0 argument_texte sauts_ligne {printf("\n");}
  165.         | sauts0_ligne  CMD_HEADER error sauts_ligne {printf("\n.\\\"ERROR\n");yyerrok;fprintf(stderr,":HEADER badly formed!\n");}
  166.         ;
  167. header_section    : CMD_SECTION {printf(".SH ");}  espaces0 argument_texte sauts_ligne {printf("\n");}
  168.         | CMD_SSECTION {printf(".SS ");}  espaces0 argument_texte sauts_ligne {printf("\n");}
  169.         | CMD_SECTION error sauts_ligne {printf("\n.\\\"ERROR\n");yyerrok;fprintf(stderr,":SECTION badly formed!\n");}
  170.         | CMD_SSECTION error sauts_ligne {printf("\n.\\\"ERROR\n");yyerrok;fprintf(stderr,":SSECTION badly formed!\n");}
  171.         ;
  172.  
  173. /* DOCUMENT */
  174.  
  175. corps_page    : liste_section
  176.         ;
  177. liste_section    : section
  178.         | liste_section section
  179.         ;
  180. section : header_section corps_section
  181.         ;
  182.  
  183. corps_section    : bloc0
  184.         |
  185.         ;
  186.  
  187. paragraphe    :  espaces0   texte_riche sauts_ligne {printf("\n");}
  188.         |  espaces0 error sauts_ligne {printf("\n.\\\"ERROR\n");yyerrok;fprintf(stderr,"Paragraph badly formed!\n");}
  189.         ;
  190. paragraphe_opt  :   sauts_ligne
  191.         |  paragraphe
  192.         ;
  193. paragraphe_relatif : {printf(".IP\n");}  paragraphe  
  194.         ;
  195. label_item    : espaces0  TOK_BEGIN espaces0 texte_riche_quote espaces0 TOK_END
  196.         | espaces0  TOK_BEGIN error TOK_END {printf("\n.\\\"ERROR\n");yyerrok;fprintf(stderr,"Label badly formed!\n");}
  197.         ;
  198. un_item        : {printf(".IP \"");} label_item {printf("\"\n");} paragraphe_opt
  199.         | error sauts_ligne {printf("\n.\\\"ERROR\n");yyerrok;fprintf(stderr,"Labeled paragraph badly formed!\n");}
  200.         ;
  201.  
  202. bloc0        : bloc0b
  203.         | bloc0i
  204.         ;
  205. bloc0b        :  {printf(".\\\"bloc1[\n");} bloc1 {printf(".\\\"bloc1]\n");}
  206.         | bloc0i {printf(".\\\"bloc1[\n");} bloc1 {printf(".\\\"bloc1]\n");}
  207.         ;
  208. bloc0i        : paragraphe
  209.         | bloc0  {printf(".PP\n");} paragraphe
  210.         ;
  211.  
  212. bloc1        : bloc1i
  213.         | bloc1b
  214.         ;
  215. bloc1i        : item1
  216.         | bloc1 item1
  217.         ;
  218. bloc1b        : bloc1i {printf(".RS\n.\\\"bloc2[\n");} bloc2 {printf(".RE\n.\\\"bloc2]\n");}
  219.         ;
  220. item1        : TOK_ITEM1     un_item   
  221.         | TOK_INDENT1 paragraphe_relatif
  222.         ;
  223.  
  224. bloc2        : bloc2i
  225.         | bloc2b
  226.         ;
  227. bloc2i        : item2
  228.         | bloc2 item2
  229.         ;
  230. bloc2b        : bloc2i {printf(".RS\n.\\\"bloc3[\n");} bloc3 {printf(".RE\n.\\\"bloc3]\n");}
  231.         ;
  232. item2        : TOK_ITEM2 un_item
  233.         | TOK_INDENT2 paragraphe_relatif
  234.         ;
  235. bloc3        : item3
  236.         | bloc3 item3
  237.         ;
  238. item3        : TOK_ITEM3 un_item
  239.         | TOK_INDENT3 paragraphe_relatif
  240.         ;
  241.  
  242. %%
  243. /* -------------- body section -------------- */
  244.